namespace cnVery.bbs.Controls
{
    using cnVery.bbs.Entity;
    using cnVery.bbs.Kernel;
    using System;
    using System.Text;
    using System.Web.UI;

    public class TableHeader : Control
    {
        private SwitchStateEnum _switchState;
        private string _switchTableid;
        private string _title;

        public TableHeader()
        {
            this._title = string.Empty;
            this._switchState = SwitchStateEnum.Expanded;
        }

        public TableHeader(string title)
        {
            this._title = title;
            this._switchState = SwitchStateEnum.Expanded;
        }

        private string GetContent()
        {
            Skin skin = new Skin();
            StringBuilder builder = new StringBuilder(skin.TableHeaderModule);
            string skinName = skin.SkinName;
            if (this._switchTableid == null)
            {
                builder.Replace("$Switcher", "");
            }
            else
            {
                builder.Replace("$Switcher", "<img src='skin/$skin/icon/folder_" + ((this._switchState == SwitchStateEnum.Expanded) ? "open" : "close") + ".gif' align='absmiddle' style='cursor:hand' onclick=\"javascript:collapse(this, '" + this._switchTableid + "')\" />");
            }
            builder.Replace("$Title", this._title);
            builder.Replace("$skin", skinName);
            return builder.ToString();
        }

        protected override void Render(HtmlTextWriter output)
        {
            output.Write(this.GetContent());
        }

        public SwitchStateEnum SwitchState
        {
            get
            {
                return this._switchState;
            }
            set
            {
                this._switchState = value;
            }
        }

        public string SwitchTableId
        {
            get
            {
                return this._switchTableid;
            }
            set
            {
                this._switchTableid = value;
            }
        }

        public string Title
        {
            get
            {
                return this._title;
            }
            set
            {
                this._title = value;
            }
        }
    }
}

